package com.tang.managementdemo.mapper;

import com.tang.managementdemo.pojo.EmpQueryParam;
import com.tang.managementdemo.pojo.Employ;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface EmpMapper {
    @Select("select e.*,d.name as dept_name from emp e left join dept d on e.dept_id = d.id")
     List<Employ> findAll();

//    @Select("select count(*) from emp e left join dept d on e.dept_id=d.id")
//    public long count();
//
//    @Select("select e.*,d.name as dept_name from emp e left join dept d on e.dept_id = d.id limit #{start}, #{pageSize}")
//    List<Employ> page(Integer start,Integer pageSize);

//    @Select("select e.*,d.name as dept_name from emp e left join dept d on e.dept_id = d.id where e.name like CONCAT('%',#{name},'%')")
     List<Employ> list(EmpQueryParam empQueryParam);

    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into emp(username, name, gender, phone, job, salary, image, entry_date, dept_id, create_time, update_time) " +
            "values (#{username},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    void insert(Employ employ);

    void deleteById(List<Integer> id);

    Employ getById(Integer id);

//    @Update("update emp set username = #{username},name = #{name},gender = #{gender},phone = #{phone},job = #{job},salary = #{salary},image = #{image},entry_date = #{entryDate},dept_id = #{deptId},update_time = #{updateTime} where id = #{id}")
    void update(Employ employ);

    //查询所有职位员工数
    @MapKey("pos")
    List<Map<String, Object>> countEmpJobData();

    //统计员工性别信息
    @MapKey("name")
    List<Map> countGenderData();
}
